<?
include_once(CONFIG_DOCUMENT_ROOT.'includes/lib/core.class.php');

class Template extends Core {

	public static $instancia = null;
	private $_template = null;
	protected $autorender = true;
	private $content = null;
	private $data = null;

	function __construct ($template=null) {
		parent::__construct();
		$this->_template = CONFIG_DEFAULT_TEMPLATE;
		if ($template)
			$this->template($template);
	}

	/**
	 * Devuelve una unica instancia de esta clase
	 * 
	 * @return object Instancia de esta clase
	 */
	public static function getInstance() {
		if (!self::$instancia instanceof self)
			self::$instancia = new self;
		return self::$instancia;
	}

	function autorender ($autorender=null) {
		if ($autorender!==null)
			$this->autorender = (boolean)$autorender;
		return $this->autorender;
	}

	function template ($template=null) {

		if ($template!==null)
			$this->_template = $template;

		return $this->_template;
	}

	function data ($data) {
		$this->data = $data;
	}

	function content ($content=null) {

		if ($content)
			$this->content = $content;

		return $this->content;
	}

	function render ($template=null, $content=null) {

		if ($template)
			$this->template($template);
		
		if ($content)
			$this->content($content);

		//if (!$this->autorender())
		//	return false;

		if (!$this->template())
			return false;

		$data = $this->load->data();

		// Obtengo el template
		$tpl = CONFIG_DOCUMENT_ROOT.'includes/templates/'.$this->_template.'/index.tpl';

		// Incluyo el template y retorno
		return include($tpl);

	}
}

?>
